﻿Imports iConverter.Contracts
Imports System.Drawing
Imports System.Configuration


''' <summary>
''' 表示一个插件的抽象实现
''' </summary>
''' <typeparam name="TSettings">用于保存插件设置的强类型</typeparam>
''' <remarks></remarks>
Public MustInherit Class Plugin(Of TSettings As ApplicationSettingsBase)
    Implements IPlugin, IPluginMetadata



    ''' <summary>
    ''' 创建新的实例
    ''' </summary>
    ''' <param name="type">插件类型</param>
    ''' <param name="id">ID</param>
    ''' <param name="name">名称</param>
    ''' <param name="description">描述</param>
    ''' <param name="lIcon">大图标（32 X 32）</param>
    ''' <param name="sIcon">小图标（16 x 16）</param>
    ''' <remarks></remarks>
    Sub New(ByVal type As PluginTypes,
            ByVal id As Guid,
            ByVal name As String,
            ByVal description As String,
            ByVal lIcon As Bitmap,
            ByVal sIcon As Bitmap)


        Me._pluginType = type

        Me._id = id
        Me._name = name
        Me._description = description
        Me._icon = lIcon
        Me._smallIcon = sIcon


    End Sub




#Region "插件设置关联"

    ''' <summary>
    ''' 获取或设置插件提供器的实例
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected Friend Property Provider As PluginProvider(Of TSettings)


    ''' <summary>
    ''' 获取插件设置的对象
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>
    ''' 注:如果插件不需要配置，则会返回Nothing
    ''' </remarks>
    Protected ReadOnly Property Settings As TSettings
        Get
            Return If(Me.Provider IsNot Nothing, Me.Provider.Settings, Nothing)
        End Get
    End Property


#End Region



#Region "IPlugin 实现"


    ''' <summary>
    ''' 插件类型
    ''' </summary>
    ''' <remarks></remarks>
    Dim _pluginType As PluginTypes


    ''' <summary>
    ''' 获取一个值，来指示插件是否可以运行。
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CheckCanRun As Boolean Implements Contracts.IPlugin.CheckCanRun
        Get
            Return CheckRun()
        End Get
    End Property

    ''' <summary>
    ''' 插件类型
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property PluginType As Contracts.PluginTypes Implements Contracts.IPlugin.PluginType
        Get
            Return _pluginType
        End Get
    End Property


    ''' <summary>
    ''' 检查插件是否可以正确运行
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected MustOverride Function CheckRun() As Boolean


#End Region





#Region "IPluginMetadata 实现"




    ''' <summary>
    ''' ID 
    ''' </summary>
    ''' <remarks></remarks>
    Dim _id As Guid

    ''' <summary>
    ''' 描述
    ''' </summary>
    Dim _description As String

    ''' <summary>
    ''' 名字
    ''' </summary>
    Dim _name As String

    ''' <summary>
    ''' 图标
    ''' </summary>
    Dim _icon As Drawing.Bitmap

    ''' <summary>
    ''' 小图标
    ''' </summary>
    Dim _smallIcon As Drawing.Bitmap

    ''' <summary>
    ''' 描述
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Description As String Implements Contracts.IBaseMetadata.Description
        Get
            Return _description
        End Get
    End Property



    ''' <summary>
    ''' 名字
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Name As String Implements Contracts.IBaseMetadata.Name
        Get
            Return _name
        End Get
    End Property

    ''' <summary>
    ''' 图标
    ''' </summary>
    ''' <value></value>
    ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
    ''' <remarks>大小在32*32内为最佳</remarks>
    Public ReadOnly Property Icon As System.Drawing.Bitmap Implements Contracts.IPluginMetadata.Icon
        Get
            Return _icon
        End Get
    End Property

    ''' <summary>
    ''' 小图标
    ''' </summary>
    ''' <value></value>
    ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
    ''' <remarks>用于显示在菜单中（16 x 16 )小图标</remarks>
    Public ReadOnly Property SmallIcon As System.Drawing.Bitmap Implements Contracts.IPluginMetadata.SmallIcon
        Get
            Return _smallIcon
        End Get
    End Property

    ''' <summary>
    ''' ID
    ''' </summary>
    Public ReadOnly Property ID As System.Guid Implements Contracts.IPluginMetadata.ID
        Get
            Return _id
        End Get
    End Property

#End Region



End Class
